﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace combinationControl
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void LoadData(object sender,EventArgs e)
        {
            pager1.SetPageCtrl(pager1.pageIndex, pager1.pageSize, 100);
            string sql = string.Format(
                @"select top {0}* 
                from(
                select ROW_NUMBER() over (order by 病历ID) AS RowNumber,* from 
                (
                select top 100* 
                from (SELECT a.病历ID,专科病历名称,操作时间,元素名称 
                from [dbo].[医生_专科病历表] as a
                join [dbo].[医生_专科病历明细表] as b on a.病历ID=b.病历ID) as c
                ) as f
                ) as d
                where RowNumber >{1}", 5, pager1.pageIndex
            );
            DataTable dt = SqlHelper.ExecuteDataSet(sql).Tables[0];
            gridControl1.DataSource = dt;
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            //pager1.SetPageCtrl(pager1.pageIndex, pager1.pageSize, 100);
            string sql = string.Format(
                @"select top {0}* 
                from(
                select ROW_NUMBER() over (order by 病历ID) AS RowNumber,* from 
                (
                select top 100* 
                from (SELECT a.病历ID,专科病历名称,操作时间,元素名称 
                from [dbo].[医生_专科病历表] as a
                join [dbo].[医生_专科病历明细表] as b on a.病历ID=b.病历ID) as c
                ) as f
                ) as d
                where RowNumber >{1}", 5, 1
            );
            pager1.SetPageCtrl(1, pager1.pageSize, 100);
            DataTable dt = SqlHelper.ExecuteDataSet(sql).Tables[0];
            gridControl1.DataSource = dt;
            pager1.CurrentPageChange+=new EventHandler(LoadData);
            
            //pager1.SetPageCtrl(1,pager1.pageSize,);
        }

        private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            DataRow dr = gridView1.GetFocusedDataRow();
            string receice=dr["病历ID"].ToString();
            string sql = string.Format(
                @"SELECT 专科病历内容,门诊号,就诊ID,操作时间 FROM [dbo].[医生_专科病历表] where 病历ID={0}",receice
            );
            DataTable dt = SqlHelper.ExecuteDataSet(sql).Tables[0];
            gridControl2.DataSource = dt;
        }
    }
}
